package com.cj.flowabletest.service;

import com.cj.flowabletest.mapper.UserMapper;
import com.cj.flowabletest.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author cc
 * @date 2025-03-03 15:26
 **/
@Service
public class UserDetailService  implements UserDetailsService {


    @Autowired
    UserMapper userMapper;


    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        User user = userMapper.loadUserByUsername(s);
        if (user == null){
            throw new UsernameNotFoundException("用户名不存在");
        }

        user.setRoles(userMapper.getUserRoleByUserId(user.getId()));
        return user;
    }
}
